﻿
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UtilZ.Dotnet.Ex.Base;
using UtilZ.Dotnet.Ex.Communication.Net.Base;
using UtilZ.Dotnet.Ex.ZLog;

namespace UtilZ.Dotnet.Ex.Communication.Base
{
    /// <summary>
    /// 空网络传输数据分包器,即不输出数据
    /// </summary>
    public class EmptyUnpacker : UnpackerAbs
    {
        private static EmptyUnpacker _instance = null;
        /// <summary>
        /// 空网络传输数据分包器实例
        /// </summary>
        public static EmptyUnpacker Instance
        {

            get
            {
                if (_instance == null)
                {
                    _instance = new EmptyUnpacker();
                }

                return _instance;
            }
        }


        /// <summary>
        /// 构造函数
        /// </summary>
        public EmptyUnpacker()
        {

        }

        /// <summary>
        /// 对数据进行拆包
        /// </summary>
        /// <param name="unpackerPara">分包参数</param>
        /// <returns>拆包成功的数据长度</returns>
        protected override int PrimitiveUnPackge(IUnpackerPara unpackerPara)
        {
            var np = (TcpUnpackerPara)unpackerPara;
            ZLoger.Warn($"收到来自远端\"{NetHelper.GetIPPortString(((NetLinkInfo)np.LinkInfo).RemoteEndPoint)}\"的数据,但是未作处理...");
            return np.DataLength;
        }
    }
}
